import React from 'react';
import {connect} from 'dva';
import {Table, Row, Col, Form, Input, InputNumber, Select, Button, Modal, Tabs, Steps, DatePicker, message} from 'antd';
import BizParams from '../commons/BizParams'
import OperatorConstant from "../../utils/OperatorConstant";
import CurrencySelect from '../../components/commons/CurrencySelect';
import SingleDragger from "../../components/commons/SingleDragger";
import Constants from "../../utils/Constants";
const FormItem = Form.Item;
const Option = Select.Option;
const TabPane = Tabs.TabPane;
const R=require("ramda");
const Step = Steps.Step;
const dateFormat = 'YYYY-MM-DD';
import moment from 'moment'

const forexPurchaseDetail = Form.create()(class ForexPurchaseDetail extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            open: false,
            id: null,
            type: null,
            disabled: true,
            applicationUrl: "",
            exchangeUrl: "",
            serviceChargeUrl: "",
            cableChargeUrl: "",
        }
    }

    handleOpen= (id, type, disabled) => {
        this.setState({ open: true, id, type, disabled });
    }


    handleCancel = () => {
        this.setState({ open: false });
        this.props.form.resetFields();
        this.props.dispatch({
            type: "forexPurchase/refreshState",
            payload: {
                forexPurchase: {},
                cstAmtList: {}
            }
        });

        this.props.dispatch({
            type: 'capital/setNode',
            payload: {
                node: {},
            }
        });
    }

    handleConfirm = (type) =>{
        this.props.form.validateFields((errors, values) => {
            if (errors) return;
            values.id = this.state.id ? this.state.id : null;
            values.payTime = values.payTime.format(dateFormat);
            values.exchangetime = values.exchangetime ? values.exchangetime.format(dateFormat) : "";

            if(values.payAmount > values.balance){
                message.error("付款金额不能大于客户余额!");
                return;
            }

            let fun = "";
            if(this.state.type === OperatorConstant.add){
                fun = 'forexPurchase/create'
                values.status = "1";
            }
            if(this.state.type === OperatorConstant.edit){
                fun = 'forexPurchase/update'

                let isSubmit = type === OperatorConstant.add ? false : true;
                if(isSubmit){
                    values.status = "2";
                    if(this.refs.applicationUrl.getUrl()=="") {message.error("请上传购汇申请单!"); return;}
                }
                values.applicationUrl = R.isNil(this.refs.applicationUrl.getUrl())?'':this.refs.applicationUrl.getUrl();
            }
            if(this.state.type === OperatorConstant.forexpurchase){
                fun = 'forexPurchase/update'

                let isSubmit = type === OperatorConstant.add ? false : true;
                if(isSubmit){
                    values.status = "4";
                    if(this.refs.exchangeUrl.getUrl()=="") {message.error("请上传付汇水单!"); return;}
                    if(this.refs.serviceChargeUrl.getUrl()=="") {message.error("请上传手续费!"); return;}
                    if(this.refs.cableChargeUrl.getUrl()=="") {message.error("请上传电报费!"); return;}
                }
                values.exchangeUrl = R.isNil(this.refs.exchangeUrl.getUrl())?'':this.refs.exchangeUrl.getUrl();
                values.serviceChargeUrl = R.isNil(this.refs.serviceChargeUrl.getUrl())?'':this.refs.serviceChargeUrl.getUrl();
                values.cableChargeUrl = R.isNil(this.refs.cableChargeUrl.getUrl())?'':this.refs.cableChargeUrl.getUrl();
            }

            if(!R.equals(R.pick(Object.keys(values),this.props.forexPurchase.forexPurchase),values)){
                this.props.dispatch({
                    type: fun,
                    payload:{
                        ...values,
                        onSuccess:() =>{
                            this.handleCancel();
                            if(this.props.refreshList) this.props.refreshList();
                        }
                    }
                })
            }
        });
    }

    handleApproval = () =>{
        this.props.form.validateFields((errors, values) => {
            if (errors) return;
            let form = {};
            form.id = this.state.id;
            form.entityid = this.state.id;
            form.approvalresult = values.approvalresult;
            form.approvalmemo = values.approvalmemo;
            form.businesstype = Constants.FXPURCHASE;
            form.appCode = Constants.APPCODE;

            this.props.dispatch({
                type: "forexPurchase/approvalPurchase",
                payload: {
                    ...form,
                    onSuccess:() => {
                        this.handleCancel();
                        if (this.props.refreshList) this.props.refreshList();
                    }
                }
            })
        })
    }

    handleReview = () =>{
        this.props.form.validateFields((errors, values) => {
            if (errors) return;
            let form = {};
            form.entityid = this.state.id;
            form.approvalresult = values.approvalresult === "2" ? "5" : "6";
            form.approvalmemo = values.approvalmemo;
            form.businesstype = Constants.FXPURCHASE;

            this.props.dispatch({
                type: "forexPurchase/reviewPurchase",
                payload: {
                    ...form,
                    onSuccess: () => {
                        this.handleCancel();
                        if (this.props.refreshList) this.props.refreshList();
                    }
                }
            })
        })
    }


    handleChange = (e) => {
        this.props.form.setFieldsValue({providerId: '', payeeId: '', payMan: '', payeeAccount: '', payAccount: '' });
        this.props.dispatch({ type: 'outbuyPayer/refreshState', payload: { list: [] } });

        this.props.dispatch({ type: 'forexPurchase/getCstAmtById', payload: { id: R.isNil(e) ? "" : e }});
        this.props.dispatch({ type: "customerManage/queryCstRecAccs", payload: { cstid: R.isNil(e) ? "" : e, status: "1" }});
        this.props.dispatch({ type: "outbuyProvider/queryBuyerAllById", payload: { cstId: R.isNil(e) ? "" : e }});
    };

    handleChangeBuyer = (e) => {
        this.props.form.setFieldsValue({payeeId: '', payeeAccount: '' });
        this.props.dispatch({ type: 'outbuyPayer/queryOutbuyPayerListById', payload: { providerId: R.isNil(e) ? "" : e }});
    };

    setPayeeMan = (e) =>{
        let payeeManList = this.props.outbuyPayer.list ? this.props.outbuyPayer.list : [];
        R.map((row) => {
            if(row.id === e){
                this.props.form.setFieldsValue({payeeAccount: row.account});
            }
        }, payeeManList);
    }

    setPayMan = (e) =>{
        let recAccsList = this.props.customerManage.recAccsList ? this.props.customerManage.recAccsList : [];
        R.map((row) => {
            if(row.id+"" === e){
                this.props.form.setFieldsValue({payAccount: row.payeeno});
            }
        }, recAccsList);
    }

    setFxAmountByPay = (e) =>{
        let fxAmount = "";
        let prospectRate = this.props.form.getFieldValue("prospectRate") ? this.props.form.getFieldValue("prospectRate") : "";
        fxAmount = e && prospectRate ? Math.round((e/prospectRate) * 100) / 100 : "";

        this.props.form.setFieldsValue({ fxAmount: fxAmount });

    }

    setFxAmountByRate = (e) =>{
        let fxAmount = "";
        let payAmount = this.props.form.getFieldValue("payAmount") ? this.props.form.getFieldValue("payAmount") : "";
        fxAmount = payAmount && e ? Math.round((payAmount/e) * 100) / 100 : "";

        this.props.form.setFieldsValue({ fxAmount: fxAmount });
    }

    appvoralRecordColumns = [
        {title: '任务id', dataIndex: 'taskid', key: 'taskid'},
        {title: '节点', dataIndex: 'nodeid', key: 'nodeid'},
        {title: '审核人员', dataIndex: 'creatorName', key: 'creatorName'},
        {title: '审核意见', dataIndex: 'memo', key: 'memo'},
        {title: '提交时间', dataIndex: 'createtime', key: 'createtime'},
    ];

    render(){
        const { getFieldDecorator } = this.props.form;
        let formItemLayout = { labelCol: { span: 7 }, wrapperCol: { span: 14 } };

        let dataSource = this.props.forexPurchase.forexPurchase ? this.props.forexPurchase.forexPurchase : {};

        if (!R.isNil(dataSource)) {
            this.state.applicationUrl=dataSource.applicationUrl;
            this.state.exchangeUrl=dataSource.exchangeUrl;
            this.state.serviceChargeUrl=dataSource.serviceChargeUrl;
            this.state.cableChargeUrl=dataSource.cableChargeUrl;

        }

        let addButtonView = this.state.type === OperatorConstant.add || this.state.type === OperatorConstant.edit || this.state.type === OperatorConstant.forexpurchase ? true : false;
        let updateButtonView = this.state.type === OperatorConstant.edit || this.state.type === OperatorConstant.forexpurchase ? true : false;
        let appvocalButtonView = this.state.type == OperatorConstant.approval ? true : false;
        let reviewButtonView = this.state.type == OperatorConstant.review ? true : false;
        let confirmed = this.state.type === OperatorConstant.confirmed ? true : false;


        let footer = [
            <Button key="save" size="large" loading={this.props.loading} onClick={this.handleConfirm.bind(this, OperatorConstant.add)}
                    style={{ display: addButtonView ? 'inline-block' : 'none' }}>保存</Button>,

            <Button key="submit" size="large" loading={this.props.loading} onClick={this.handleConfirm.bind(this, OperatorConstant.saveAndApproval)}
                    style={{ display: updateButtonView ? 'inline-block' : 'none' }}>保存并提交</Button>,

            <Button key="appvocal" size="large" type="primary" loading={this.props.loading} onClick={this.handleApproval.bind(this)}
                    style={{ display: appvocalButtonView ? 'inline-block' : 'none' }}>审核</Button>,

            <Button key="review" size="large" type="primary" loading={this.props.loading} onClick={this.handleReview.bind(this)}
                    style={{ display: reviewButtonView ? 'inline-block' : 'none' }}>复核</Button>,

            <Button key="cancel" size="large" loading={this.props.loading} onClick={this.handleCancel.bind(this)}>{this.state.disabled ? "关闭" : "取消"}</Button>
        ];

        let node = this.props.capital.node;
        let nodename =""
        let step = "";
        let role =[];
        let isbypass = node.isbypass;




        //当前用户拥有的角色
        if(!R.isNil(node.roles) && !R.isEmpty(node.roles)){
            for(let i=0; i< node.roles.length; i++){
                role.push(node.roles[i].roleId);
            }
        }

        //越级审核
        if(isbypass == 1){
            let approvalRoles =[];

            //审核链角色
            let approvalRole = node.approvalRole;

            let flag = false;
            if(!R.isNil(node.list) && !R.isEmpty(node.list)){
                if(approvalRole == node.list[i].role){
                    flag = true;
                }

                if(flag && R.isNil(node.list[i].role) && R.isEmpty(node.list[i].role) ){
                    approvalRoles.push(node.list[i].role);
                }
            }


        }else{
            if(!R.isNil(node.list) && !R.isEmpty(node.list) &&  !R.isEmpty(node.roles)){
                let currentNode = 0;

                for(let i=0; i< node.list.length; i++){
                    if(node.nodeName == node.list[i].name){
                        currentNode = i;
                        nodename += "：当前审核节点【" + node.list[i].name + "】";
                        break;
                    }

                }

                for(let i=0; i< node.roles.length; i++){
                    role.push(node.roles[i].roleId);
                }

                step = <Steps current={currentNode} style={{width: '95%'}}>
                    {
                        R.isNil(node.list) || R.isEmpty(node.list)  ? <Step title=""></Step>
                            :
                            node.list.map(item => {
                                return (<Step title={item.name}></Step>);
                            })
                    }
                </Steps>
            }

        }

        let customerList  = this.props.customerManage.cstList ? this.props.customerManage.cstList : [];
        let recAccsList = this.props.customerManage.recAccsList ? this.props.customerManage.recAccsList : [];
        let buyerList = this.props.outbuyProvider.buyerList ? this.props.outbuyProvider.buyerList : [];
        let payeeManList = this.props.outbuyPayer.list ? this.props.outbuyPayer.list : [];
        let cstAmt = this.props.forexPurchase.cstAmtList ? this.props.forexPurchase.cstAmtList : {};


        return(
            <Modal maskClosable={false} visible={this.state.open} width={900} title={ R.isEmpty(step) ? "购汇详情" : step }
                   confirmLoading={this.props.loading} onCancel={this.handleCancel.bind(this)} footer={footer}>
                <Form>
                    <Tabs tabPosition={'top'}>
                        <TabPane tab="客户信息" key="1">
                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="客户"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('cstid', {
                                            rules: [{
                                                required: true, message: '请选择客户！',
                                            }],
                                            initialValue: dataSource.cstid
                                        })(
                                            <Select disabled={this.state.disabled} style={{width: '100%'}} showSearch
                                                    placeholder="可通过输入关键字搜索" onChange={value => this.handleChange(value)}
                                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                                                {
                                                    (R.isNil(customerList) ? [] : customerList).map(item => {
                                                        return (<Select.Option value={item.id} key={item.id}>{item.companyname}</Select.Option>);
                                                    })
                                                }
                                            </Select>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="商品供应商"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('providerId', {
                                            rules: [{
                                                required: true, message: '请选择商品供应商！',
                                            }],
                                            initialValue: dataSource.providerId
                                        })(
                                            <Select disabled={this.state.disabled} style={{width: '100%'}}
                                                    placeholder="可通过输入关键字搜索" showSearch onChange={value => this.handleChangeBuyer(value)}
                                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                                                {
                                                    (R.isNil(buyerList) ? [] : buyerList).map(item => {
                                                        return (<Select.Option value={item.id} key={item.id}>{item.name}</Select.Option>);
                                                    })
                                                }
                                            </Select>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="总金额"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('amount', {
                                            rules: [{
                                                required: true, message: '请输入总金额！',
                                            }],
                                            initialValue: cstAmt.amount ? cstAmt.amount : 0
                                        })(
                                            <Input disabled={true}/>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="余额"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('balance', {
                                            rules: [{
                                                required: true, message: '请输入余额',
                                            }],
                                            initialValue: cstAmt.balance ? cstAmt.balance : 0
                                        })(
                                            <Input disabled={true}/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>
                        </TabPane>
                    </Tabs>

                    <Tabs tabPosition={'top'} style={{ marginTop: 30 }}>
                        <TabPane tab="购汇信息" key="1">

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="收款人"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payeeId', {
                                            rules: [{
                                                required: true, message: '请输入收款人',
                                            }],
                                            initialValue: dataSource.payeeId
                                        })(
                                            <Select disabled={this.state.disabled} style={{width: '100%'}}
                                                    placeholder="可通过输入关键字搜索" showSearch onChange={value => this.setPayeeMan(value)}
                                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                                                {
                                                    (R.isNil(payeeManList) ? [] : payeeManList).map(item => {
                                                        return (<Select.Option value={item.id} key={item.id}>{item.name}</Select.Option>);
                                                    })
                                                }
                                            </Select>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="收款账号"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payeeAccount', {
                                            rules: [{
                                                required: true, message: '请输入收款账号！',
                                            }],
                                            initialValue: dataSource.payeeAccount
                                        })(
                                            <Input disabled={true}/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="	收汇币种"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payeeAmountunit', {
                                            rules: [{
                                                required: true, message: '请输入收汇币种',
                                            }],
                                            initialValue: dataSource.payeeAmountunit
                                        })(
                                            <CurrencySelect disabled={this.state.disabled}/>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="收款人国家"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('country', {
                                            rules: [{
                                                required: true, message: '请选择收款人国家',
                                            }],
                                            initialValue: dataSource.country
                                        })(
                                            <BizParams sprCode={"country"} style={{width: '100%'}} blank={true}
                                                       disabled={this.state.disabled}/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="收款银行"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payeeBank', {
                                            rules: [{
                                                required: true, message: '请输入收款银行',
                                            }],
                                            initialValue: dataSource.payeeBank
                                        })(
                                            <Input disabled={this.state.disabled} maxLength="200"/>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="收款银行地址"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payeeAddress', {
                                            rules: [{
                                                required: true, message: '请输入收款银行地址',
                                            }],
                                            initialValue: dataSource.payeeAddress
                                        })(
                                            <Input disabled={this.state.disabled} maxLength="300"/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>


                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款人"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payMan', {
                                            rules: [{
                                                required: true, message: '请输入付款人',
                                            }],
                                            initialValue: dataSource.payMan
                                        })(
                                            <Select disabled={this.state.disabled} style={{width: '100%'}}
                                                    placeholder="可通过输入关键字搜索" showSearch onChange={value => this.setPayMan(value)}
                                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                                                {
                                                    (R.isNil(recAccsList) ? [] : recAccsList).map(item => {
                                                        return (<Select.Option value={item.id +""} key={item.id}>{item.payeename}</Select.Option>);
                                                    })
                                                }
                                            </Select>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款账号"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payAccount', {
                                            rules: [{
                                                required: true, message: '请输入付款账号',
                                            }],
                                            initialValue: dataSource.payAccount
                                        })(
                                            <Input disabled={true}/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款金额(CNY)"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payAmount', {
                                            rules: [{
                                                required: true, message: '请输入付款金额(CNY)',
                                            }],
                                            initialValue: dataSource.payAmount
                                        })(
                                            <InputNumber disabled={this.state.disabled} style={{width: '100%'}} onChange={value => this.setFxAmountByPay(value)}
                                                maxLength="18"
                                            />
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="购汇理由"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('purchaseReason', {
                                            rules: [{
                                                required: true, message: '请输入购汇理由',
                                            }],
                                            initialValue: dataSource.purchaseReason
                                        })(
                                            <Input disabled={this.state.disabled} maxLength="300"/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="预估汇率"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('prospectRate', {
                                            rules: [{
                                                required: true, message: '请输入预估汇率',
                                            }],
                                            initialValue: dataSource.prospectRate
                                        })(
                                            <InputNumber disabled={this.state.disabled} style={{width: '100%'}} onChange={value => this.setFxAmountByRate(value)}
                                                maxLength="18"
                                            />
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付汇金额"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('fxAmount', {
                                            rules: [{
                                                required: true, message: '请输入付汇金额',
                                            }],
                                            initialValue: dataSource.fxAmount
                                        })(
                                            <Input disabled={true}/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付汇方式"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('settlement', {
                                            rules: [{
                                                required: true, message: '请输入付汇方式',
                                            }],
                                            initialValue: dataSource.settlement
                                        })(
                                            <BizParams sprCode='settlement' disabled={this.state.disabled}/>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款时间"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payTime', {
                                            rules: [{
                                                required: true, message: '请输入付款时间',
                                            }],
                                            initialValue: dataSource.payTime ? moment(dataSource.payTime, dateFormat) : ''
                                        })(
                                            <DatePicker disabled={this.state.disabled}
                                                        style={{width: '100%'}}
                                                        showTime={{format: 'YYYY-MM-DD'}}
                                                        format="YYYY-MM-DD"
                                                        placeholder="请选择时间"
                                            />
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            <Row>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款方式"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payType', {
                                            rules: [{
                                                required: true, message: '请输入付款方式',
                                            }],
                                            initialValue: dataSource.payType
                                        })(
                                            <Select disabled={this.state.disabled}>
                                                <Select.Option value="1">预付货款</Select.Option>
                                                <Select.Option value="2">货到付款</Select.Option>
                                                <Select.Option value="3">退款</Select.Option>
                                                <Select.Option value="4">其他</Select.Option>
                                            </Select>
                                        )}
                                    </FormItem>
                                </Col>
                                <Col span={12}>
                                    <FormItem
                                        {...formItemLayout}
                                        label="付款银行地址"
                                        hasFeedback
                                    >
                                        {getFieldDecorator('payAddress', {
                                            rules: [{
                                                required: true, message: '请输入付款银行地址',
                                            }],
                                            initialValue: dataSource.payAddress
                                        })(
                                            <Input disabled={this.state.disabled} maxLength="300"/>
                                        )}
                                    </FormItem>
                                </Col>
                            </Row>

                            {this.state.id ?
                                <Row>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout}
                                                  label={<span className="ant-form-item-required">购汇申请单</span>}
                                                  hasFeedback>
                                            <SingleDragger
                                                url={R.isNil(this.state.applicationUrl) ? '' : this.state.applicationUrl}
                                                dataSource={dataSource} ref="applicationUrl"
                                                module={Constants.FXPURCHASE}
                                                disabled={this.state.disabled}/>

                                        </FormItem>
                                    </Col>
                                </Row>
                                : ""
                            }
                        </TabPane>
                    </Tabs>


                    {this.state.type === OperatorConstant.forexpurchase || confirmed || reviewButtonView ?
                        <Tabs tabPosition={'top'}>
                            <TabPane tab="补充信息" key="1">
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="发票号"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('invoiceno', {
                                                rules: [{
                                                    required: true, message: '请输入发票号！',
                                                }],
                                                initialValue: dataSource.invoiceno
                                            })(
                                                <Input disabled={ reviewButtonView || confirmed ? true : !this.state.disabled} maxLength="100"/>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="合同号"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('contractno', {
                                                rules: [{
                                                    required: true, message: '请输入合同号',
                                                }],
                                                initialValue: dataSource.contractno
                                            })(
                                                <Input disabled={reviewButtonView || confirmed ? true :  !this.state.disabled} maxLength="50"/>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>

                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="付汇时间"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('exchangetime', {
                                                rules: [{
                                                    required: true, message: '请输入付汇时间！',
                                                }],
                                                initialValue: dataSource.exchangetime ? moment(dataSource.exchangetime, dateFormat) : ''
                                            })(
                                                <DatePicker disabled={reviewButtonView || confirmed ? true : !this.state.disabled}
                                                style={{width: '100%'}}
                                                showTime={{format: 'YYYY-MM-DD'}}
                                                format="YYYY-MM-DD"
                                                placeholder="请选择时间"
                                                />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="银行付汇汇率"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('fxRate', {
                                                rules: [{
                                                    required: true, message: '请输入银行付汇汇率！',
                                                }],
                                                initialValue: dataSource.fxRate
                                            })(
                                                <Input disabled={reviewButtonView || confirmed ? true : !this.state.disabled} maxLength="18"/>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>

                                <Row>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout}
                                                  label={<span className="ant-form-item-required">付汇水单</span>}
                                                  hasFeedback>
                                            <SingleDragger
                                                url={R.isNil(this.state.exchangeUrl) ? '' : this.state.exchangeUrl}
                                                dataSource={dataSource} ref="exchangeUrl"
                                                module={Constants.FXPURCHASE} disabled={reviewButtonView || confirmed ? true : !this.state.disabled}/>

                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout}
                                                  label={<span className="ant-form-item-required">手续费</span>}
                                                  hasFeedback>
                                            <SingleDragger
                                                url={R.isNil(this.state.serviceChargeUrl) ? '' : this.state.serviceChargeUrl}
                                                dataSource={dataSource} ref="serviceChargeUrl"
                                                module={Constants.FXPURCHASE} disabled={reviewButtonView || confirmed ? true : !this.state.disabled}/>

                                        </FormItem>
                                    </Col>
                                </Row>

                                <Row>
                                    <Col span={12}>
                                        <FormItem {...formItemLayout}
                                                  label={<span className="ant-form-item-required">电报费</span>}
                                                  hasFeedback>
                                            <SingleDragger
                                                url={R.isNil(this.state.cableChargeUrl) ? '' : this.state.cableChargeUrl}
                                                dataSource={dataSource} ref="cableChargeUrl"
                                                module={Constants.FXPURCHASE} disabled={reviewButtonView || confirmed ? true : !this.state.disabled}/>

                                        </FormItem>
                                    </Col>
                                </Row>
                            </TabPane>
                        </Tabs>
                        : ""
                    }

                    {this.state.type === OperatorConstant.approval || reviewButtonView ?
                        <Tabs tabPosition={'top'}>
                            <TabPane tab={reviewButtonView ?  "审核" : "审核" +nodename} key="1">
                                <Row>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="请选择审核结果"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('approvalresult', {
                                                rules: [{
                                                    required: true, message: '请选择审核结果！',
                                                }],
                                                initialValue: R.isNil(dataSource.approvalresult) || !R.contains(dataSource.approvalresult, ["3", "1"]) ? "" : dataSource.approvalresult
                                            })(
                                                <Select
                                                    disabled={appvocalButtonView || reviewButtonView ? !this.state.disabled : this.state.disabled}>
                                                    <Option value="2">审核通过</Option>
                                                    <Option value="3">审核不通过</Option>
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={12}>
                                        <FormItem
                                            {...formItemLayout}
                                            label="备注"
                                            hasFeedback
                                        >
                                            {getFieldDecorator('approvalmemo', {
                                                rules: [{
                                                    required: this.props.form.getFieldValue('approvalresult') == "2" ? false : true,
                                                    message: '请输入备注！',
                                                }],
                                                initialValue: dataSource.approvalmemo
                                            })(
                                                <Input maxLength="100" disabled={appvocalButtonView || reviewButtonView ? !this.state.disabled : this.state.disabled}/>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </TabPane>

                            {reviewButtonView ? "" :
                                <TabPane tab="审核记录" key="2">
                                    <Table dataSource={this.props.forexPurchase.appvoralRecordList} columns={this.appvoralRecordColumns}
                                           bordered={true} size={'middle'} pagination={false} scroll={{ x: true}} />
                                </TabPane>
                            }
                        </Tabs>
                        : ""}
                </Form>
            </Modal>
        )
    }
})

function mapStateToProps(state){
    return{
        loading: state.loading.models.forexPurchase, forexPurchase: state.forexPurchase, capital: state.capital, customerManage: state.customerManage,
                        outbuyProvider: state.outbuyProvider, outbuyPayer: state.outbuyPayer
    };
}

export default connect(mapStateToProps)(forexPurchaseDetail);